/*
 * File:   templib.h
 * Author: aple
 */

#ifndef PT100_LIB_H_
#define	PT100_LIB_H_

#include "templib.h"

/* 计算顺序
 * 1、tc to temp
 * 2、CF
 * 3、coef
 * 4、correct  //修正表为coef规格化后的单位一致
 * 5、limite-err
 * 6、flt
 */

typedef struct
{
    float mV; //电压
    int32_t AdVal; //AD值
} tc_sample_type;

typedef struct
{
    uint8_t Err;    //仅TEMP_ERR_LIMITE_L_MASK 和 TEMP_ERR_LIMITE_H_MASK
    uint8_t sample_nums; //采样点数量
    uint8_t bCFEn;
    int32_t AdcVal;
	float air_temp; //实数-摄氏温度
	
    //修正
    int16_t Pb;
    int16_t Pk;
    //范围
    float TempLimiteL; //测温下限
    float TempLimiteH; //测温上限
    //输出
    float Flt;
    float TempOrg;   //未修正的原始数据
    float TempReal;   //
    float TempCtr;    //
    float TempDisp;   //
    
    float coef;       //输出值的系数 //修正值，上下限单位必须和coef后的数据一致。
    
    //整数化 二舍八入
    int16_t iTempCtr;
    int16_t iTempDisp;
    int16_t iTempOrg;
    
    //采样点
    tc_sample_type Sample[4];   //采样点，实际电阻和温度
    
    //修正模式
    uint8_t correct_point_len;
    temp_correct_mode_type correct_mode;
    void * correct_list;
	float (* t_to_v)(float t);
	float (* v_to_t)(float v);

} tc_cal_type;

float tc_k_cal(tc_cal_type *pt);
float tc_k_cal_pbpk(tc_cal_type *tc);
float tc_k_cal_imap(tc_cal_type *tc);

float tc_r_cal(tc_cal_type *pt);
float tc_r_cal_pbpk(tc_cal_type *tc);
float tc_r_cal_imap(tc_cal_type *tc);

float tc_e_cal(tc_cal_type *pt);
float tc_e_cal_pbpk(tc_cal_type *tc);
float tc_e_cal_imap(tc_cal_type *tc);

float tc_j_cal(tc_cal_type *pt);
float tc_j_cal_pbpk(tc_cal_type *tc);
float tc_j_cal_imap(tc_cal_type *tc);

float tc_s_cal(tc_cal_type *pt);
float tc_s_cal_pbpk(tc_cal_type *tc);
float tc_s_cal_imap(tc_cal_type *tc);

float tc_t_cal(tc_cal_type *pt);
float tc_t_cal_pbpk(tc_cal_type *tc);
float tc_t_cal_imap(tc_cal_type *tc);

float tc_n_cal(tc_cal_type *pt);
float tc_n_cal_pbpk(tc_cal_type *tc);
float tc_n_cal_imap(tc_cal_type *tc);

float tc_b_cal(tc_cal_type *pt);
float tc_b_cal_pbpk(tc_cal_type *tc);
float tc_b_cal_imap(tc_cal_type *tc);

#endif	/* TEMPLIB_H_ */

